package com.arges.demo;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

public class TimeDifference {
    public static void main(String[] args) {
        //Date date1 = DateUtil.parse("2022-09-07 12:23:25");
        Date date1 = new Date();
        Date date2 = DateUtil.parse("2023-02-27 18:23:25");

        System.out.println("两个时间相差 "+DateUtil.between(date1, date2, DateUnit.DAY)+" 天");
        System.out.println("两个时间相差 "+DateUtil.between(date1, date2, DateUnit.HOUR)+" 小时");
        System.out.println("两个时间相差 "+DateUtil.between(date1, date2, DateUnit.MINUTE)+" 分钟");
        System.out.println("两个时间相差 "+DateUtil.between(date1, date2, DateUnit.SECOND)+" 秒");
        System.out.println("两个时间相差 "+DateUtil.between(date1, date2, DateUnit.MS)+" 毫秒");
    }
}